{% extends "main.html" %}
{% block content %}

<div class="layui-row">
    <div class="layui-col-md12">
      <h1 align="center">GateIo列表</h1>
      
    </div>    
</div>
 <div class="layui-row">
      <div class="layui-col-md10">
        &nbsp;
      </div>
      <div class="layui-col-md1">
        <button id="add_gateio_show" class="layui-btn">增加GateIo账户</button>
      </div>
  </div>
<div class="layui-row">
    <div class="layui-col-md12">
      <table class="layui-hide" id="wallet" lay-filter="gateio_table"></table>
    </div>
    <script type="text/html" id="gateio_status">
      {% raw %}

      {{#  if(d.status == 1 ){ }}
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="info">已启用</a>
      {{# }else { }}
          <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="info">已禁用</a>
      {{# } }}

      {% endraw %}   
    </script>
    <script type="text/html" id="gateio_operation">
      {% raw %}

      {{#  if(d.status == 1 ){ }}
          <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="change">禁用</a>
      {{# }else { }}
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="change">启用</a>
      {{# } }}

      {% endraw %}   
    </script>
</div>


    <div id="add_gateio_show_div" style="display: none;">
        <form class="layui-form"> 
          <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
              <input type="text" id="name" required="" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-inline">
              <input type="text" id="phone" required="" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
          </div>


          <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
              <input type="text" id="email" required="" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">api_key</label>
            <div class="layui-input-inline">
              <input type="text" id="api_key" required="" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">secret_key</label>
            <div class="layui-input-inline">
              <input type="text" id="secret_key" required="" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
          </div>
          
        </form>
      </div>



<script type="text/javascript">
  $(document).ready(function() {  
    

  layui.use('table', function(){
    var table = layui.table;
    
    table.render({
      elem: '#wallet'
      ,url:'/user/gateio_user_list'
      ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
      ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
        layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
        ,curr: 1 //设定初始在第 5 页
        ,groups: 1 //只显示 1 个连续页码
        ,first: false //不显示首页
        ,last: false //不显示尾页
        ,limit:20
        // ,theme: '#c00' 
      }
      ,cols: [[
        {field:'id', width:240, title: 'ID', sort: true}
        ,{field:'name', width:180, title: '账户名称'}
        ,{field:'phone', width:180, title: '电话', sort: true}
        ,{field:'email', width:180, title: '邮箱', sort: true}
        ,{field:'status', width:80, title: '状态',toolbar:"#gateio_status"}
        ,{field:'operation', width:80, title: '操作',toolbar:"#gateio_operation"}
        ,{field:'ctime', title: '创建时间', sort: true}
        ,{field:'utime', title: '更新时间', sort: true}
        
      ]]
    });

    table.on('tool(gateio_table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的DOM对象
       
        if(layEvent === 'change'){ //删除
            layer.confirm('确定停用这个账户吗？', function(index){
              //向服务端发送删除指令
              oid = data.id;
              $.ajax({
                  url: "/user/change_gateio_user_info",
                  type: "POST",
                  dataType: "json",
                  data:{"oid":oid},
                  success: function (result){
                      if(result['datas']['code']=="1"){
                          layer.msg(result['msg']);
                          location.href=location.href;
                      }else{
                          layer.msg(result['msg']);
                      }
                  }
              });
              layer.close(index);
          });
        } 
    });

  });


      $("#add_gateio_show").click(function(){
          layer.open({
              type: 1
              ,title: ['增加GateIo账户', 'font-size:18px;align:center;']
              ,closeBtn: false
              ,area: ['400px', '400px']
              ,shade: 0.8
              ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
              ,btn: ['保存', '取消']
              ,btnAlign: 'c'
              ,moveType: 1 //拖拽模式，0或者1
              ,content: $('#add_gateio_show_div')
              ,success: function(layero){
                var btn = layero.find('.layui-layer-btn');
                btn.find('.layui-layer-btn0').click(function(){
                  var name = $("#name").val();
                  var phone = $("#phone").val();
                  var email = $("#email").val();
                  var api_key = $("#api_key").val();
                  var secret_key = $("#secret_key").val();
                  $.ajax({
                      url: "/user/add_gateio_user",
                      type: "POST",
                      dataType: "json",
                      data:{"name":name,"phone":phone,"email":email,"api_key":api_key,"api_key":api_key,"secret_key":secret_key},
                      success: function (result){
                          if(result['datas']['code']=="1"){
                              layer.msg(result['msg']);
                              location.href=location.href;
                          }else{
                              layer.msg(result['msg']);
                          }
                      }
                  });
                });

              }
            });
      });
    
  });
</script>
{% endblock %}